package com.zjcode.cdcer.controller;

import com.chinatechstar.component.commons.controller.BaseController;
import com.chinatechstar.component.commons.result.ListResult;
import com.chinatechstar.component.commons.result.ResultBuilder;
import com.chinatechstar.component.commons.supports.PageData;
import com.zjcode.cdcer.model.basic.JsonObj;
import com.zjcode.cdcer.service.TkmSysOrgService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:TkmSysOrgController
 * @功能：机构管理
 * @author：wlei
 * @日期：2022/8/5-04:05
 **/
@RestController
@Slf4j
@RequestMapping("/v1/orgsetting/")
public class TkmSysOrgController extends BaseController {

    @Autowired
    private TkmSysOrgService tkmSysOrgService;

    @PostMapping("listAllData")
    @ApiOperation("获取所有的机构数据")
    public ListResult<Object> listAllData(@RequestBody PageData pageData) {
        return ResultBuilder.buildListSuccess(tkmSysOrgService.listAllData(pageData));
    }

    @GetMapping("getAllProvince")
    @ApiOperation("获取所有的省份数据")
    public ListResult<Object> getAllProvince() {
        return ResultBuilder.buildListSuccess(tkmSysOrgService.getAllProvince());
    }

    @GetMapping("getAllProvinceCity")
    @ApiOperation("获取所有的省下面城市数据")
    public ListResult<Object> getAllProvinceCity() {
        PageData pageData = getPageData();
        return ResultBuilder.buildListSuccess(tkmSysOrgService.getAllProvinceCity(pageData));
    }

    @GetMapping("getDistrictAndStreet")
    @ApiOperation("获取所有的区街道信息")
    public ListResult<Object> getDistrictAndStreet() {
        PageData pageData = getPageData();
        return ResultBuilder.buildListSuccess(tkmSysOrgService.getDistrictAndStreet(pageData));
    }

    @PostMapping("exportOrgData")
    @ApiOperation("获取所有的区街道信息")
    public JsonObj exportOrgData(@RequestBody PageData pageData) {
        List<LinkedHashMap<String, Object>> list = tkmSysOrgService.exportOrgData(
                pageData);
        Map<String, Object> map = new HashedMap<>();
        map.put("data", list);
        return JsonObj.success(map);
    }
}
